package main

import (
	"fmt"
	"net/rpc"
)

func main(){
	//调用DialHTTP方法创建链接
	client,err := rpc.DialHTTP("tcp","127.0.0.1:8081")
	if err!=nil {
		panic(err)
	}
	var r float32
	r = 2
	var area *float32

	//同步调用远程服务器方法
	err = client.Call("MathUtil.CalculationArea",r,&area)
	if err!=nil {
		fmt.Println("远程服务调用失败")
		panic(err)
	}
	fmt.Println("圆面积为:",*area)

	//异步调用
	asyncClient := client.Go("MathUtil.CalculationArea",r,&area,nil)
	res := <- asyncClient.Done
	fmt.Println(res)
	fmt.Println("圆面积为:",*area)
}
